package com.intellagric.service.iftmonitor.Impl.ift_manufactor;

import com.github.pagehelper.PageHelper;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.mapper.IftManufactorMapper;
import com.intellagric.pojo.IftManufactor;
import com.intellagric.pojo.IftManufactorExample;
import com.intellagric.service.iftmonitor.ift_manufactor.ManufactorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/20
 * @DESC： 厂商信息服务接口
 */
@Service
public class ManufactorServiceImpl implements ManufactorService {

    @Autowired
    private IftManufactorMapper manufactorMapper;

    /**
     * 添加厂商信息
     * @param manufactor
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage addManufator(IftManufactor manufactor) {
        if (manufactorMapper.insertSelective(manufactor) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除厂商信息
     * @param id
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage deleteManufator(String id) {
        if (manufactorMapper.deleteByPrimaryKey(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 修改厂商信息
     * @param manufactor
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage editManufator(IftManufactor manufactor) {
        if (manufactorMapper.updateByPrimaryKeySelective(manufactor) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 查询厂商详细信息
     * @param id
     * @return IftManufactor
     */
    @Override
    public IftManufactor getManufatorById(String id) {
        return manufactorMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询厂商信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getManufatorList() {
        IftManufactorExample manufactorExample = new IftManufactorExample();
        manufactorExample.createCriteria().andIdIsNotNull();
        List<IftManufactor> manufactorList = manufactorMapper.selectByExample(manufactorExample);
        return LayuiDataGridResult.success().add(manufactorList,manufactorList.size());
    }

    /**
     * 分页查询厂商信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getManufatorPage(int page, int rows) {
        PageHelper.startPage(page,rows);
        IftManufactorExample manufactorExample = new IftManufactorExample();
        manufactorExample.createCriteria().andIdIsNotNull();
        List<IftManufactor> manufactorList = manufactorMapper.selectByExample(manufactorExample);
        return LayuiDataGridResult.success().add(manufactorList,this.getManufatorList().getCount());
    }
}
